package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class DelOperation implements IOperation{
    @Override
    public void work( BookList bookList) {
        System.out.println("请输入你要删除的图书：");
        Scanner scanner=new Scanner(System.in);

        String name=scanner.nextLine();
        int size=bookList.getUsedSize();
        int delete=0;
        for (int i=0;i<size;i++){
            if (bookList.getBook(i).getName().equals(name)){

                delete=i;
                for (int j=delete;j<size;j++){

                    Book book=bookList.getBook(j+1);
                    bookList.setBooks(j,book);


                }
                bookList.setUsedSize(size-1);
                System.out.println("删除图书");
                return;
            }
        }
        System.out.println("未找到图书");

    }
}
